package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.Response;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.vo.CourseListQuery;
import com.atguigu.eduservice.entity.vo.CoursePublish;
import com.atguigu.eduservice.entity.vo.CourseQuery;
import com.atguigu.eduservice.entity.vo.TeacherQuery;
import com.atguigu.eduservice.service.EduCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author zhaolie
 * @since 2020-12-08
 */
@RestController
@RequestMapping("/eduservice/course")
@Api(description = "课程后台")
public class EduCourseController {

    @Resource
    private EduCourseService courseService;

    // 根据课程查询基本信息
    @GetMapping("/{courseId}")
    @ApiOperation("查询课程")
    private Response getCourseInfo(@PathVariable String courseId) {
        CourseQuery course = courseService.getCourseInfo(courseId);
        return Response.SUCCESS().data("rows", course);
    }

    // 添加课程基本信息的方法
    @PostMapping
    @ApiOperation("添加课程")
    private Response addCourseInfo(@RequestBody CourseQuery courseQuery) {
        String courseId = courseService.saveCourseInfo(courseQuery);
        return Response.SUCCESS().data("courseId", courseId);
    }

    // 修改课程基本信息
    @PutMapping
    @ApiOperation("修改课程")
    private Response updateCourseInfo(@RequestBody CourseQuery courseQuery) {
        courseService.updateCourseInfo(courseQuery);
        return Response.SUCCESS();
    }

    @GetMapping("/publish/{courseId}")
    @ApiOperation("课程发布")
    private Response getPublishCourseInfo(@PathVariable String courseId) {
        CoursePublish course = courseService.publishCourseInfo(courseId);
        return Response.SUCCESS().data("rows", course);
    }

    @PutMapping("/publish/{courseId}")
    @ApiOperation("课程发布")
    private Response publishCourse(@PathVariable String courseId) {
        courseService.publishCourse(courseId);
        return Response.SUCCESS();
    }

    @ApiOperation("条件查询带分页功能")
    @PostMapping("/{current}/{limit}")
    private Response pageCourseCondition(@PathVariable Long current,
                                         @PathVariable Long limit,
                                         @RequestBody(required = false) CourseListQuery courseListQuery) {
        Map map = courseService.pageCourseCondition(current, limit, courseListQuery);
        return Response.SUCCESS().data("rows", map);
    }

    @DeleteMapping("/{courseId}")
    @ApiOperation("删除课程")
    private Response deleteCourse(@PathVariable String courseId) {
        courseService.deleteCourse(courseId);
        return Response.SUCCESS();
    }
}

